package and.roid.box;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

public class BoxOb {
	private static final double PIE = 3.1415926;
	private double obj_x, obj_y;// オブジェクト座標
	private int obj_wh;
	private int angle;// オブジェクトが進む角度
	private int speed_x;// 移動量
	private int speed_y;// 移動量
	private int color;// オブジェクトの色
	private int size;

	BoxOb(double x, double y, int wh, int d, int vxy, int col) {
		obj_x = x;
		obj_y = y;
		obj_wh = wh;
		angle = d;
		size = vxy;
		color = col;
		angle = (angle + 360) % 360;
		speed_x = (int) (Math.cos(toRadian(angle)) * size);
		speed_y = (int) -(Math.sin(toRadian(angle)) * size);
	}

	public void init() {
	}

	public void draw(Canvas c, Paint p) {
		p.setStyle(Paint.Style.FILL);
		p.setColor(color);
		c.drawRect(new Rect((int) obj_x, (int) obj_y, (int) obj_x + obj_wh, (int) obj_y + obj_wh),
				p);
	}

	public void move(int x1, int y1, int x2, int y2) {
		obj_x += speed_x;
		obj_y += speed_y;
		if (obj_x < x1 || obj_x > x2 - obj_wh)
			speed_x *= -1;
		if (obj_y < y1 || obj_y > y2 - obj_wh)
			speed_y *= -1;
	}

	public float toRadian(float deg) {
		return (float) (deg * PIE / 180);
	}

}